// pages/user/admin/manageh/modhspt/modhspt.js
var app = getApp();
var host=app.globalData.host
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		hid:0,
		hname:''
	},
	manageXm()
	{
		let that=this
		wx.navigateTo({
			url: 'modxm/modxm?hid='+that.data.hid+'&hname='+that.data.hname
		  })
	},
	doaddOffice(name)
	{
		let that=this;
		wx.request({
			url: host+'/admin/office',
			method:"POST",
			data:{
				"officeHid":that.data.hid,
				"officeName":name
			},
			success(res)
			{
				console.log(res);
				that.getOfficeList();
			}
		})
	},
	addOffice()
	{
		let that=this
		wx.showModal({
			title:"请输入科室名称",
			editable:true,
			placeholderText:"科室名称",
			success(res)
			{
				console.log(res)
				if(res.confirm)
					that.doaddOffice(res.content)
			}
		})
	},
	delHspt()
	{
		let that=this;
		wx.request({
			url: host+'/admin/hosptl',
			method:"DELETE",
			header: {
				'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
			  },
			data:{
				id:that.data.hid
			},
			success(res)
			{
				console.log(res);
				wx.navigateBack()
				wx.showToast({
				  title: '删除成功',
				  icon:"success"
				})
			}
		})
	},
	confirmdelHspt()
	{
		let that=this;
		wx.showModal({
			title:"确认删除",
			content:"确认要删除 "+that.data.hname+" 吗？",
			success(res)
			{
				console.log(res)
				if(res.confirm)
				{
					that.delHspt()
				}
			}
		})
	},
	delete(office)
	{
		console.log(office)
		wx.request({
			url: host+'/admin/office',
			method:'DELETE',
			header: {
				'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
			  },
			data:{
				"id":office.officeId
			},
			success(res)
			{
				console.log(res)
				wx.showToast({
				  title: '删除成功',
				  icon:'success'
				})
			}
		})
		this.getOfficeList()
	},
	confirmDelete(e)
	{
		console.log(e)
		var keshi=e.currentTarget.dataset.item
		let that=this
		wx.showModal({
			title:"确认删除",
			content:"确认要删除科室："+keshi.officeName,
			confirmColor:"#FF0000",
			success(res)
			{
				if(res.confirm)
				{
					that.delete(keshi)
				}
			}
		})
	},
	getOfficeList()
	{
		let that=this;
		wx.request({
			url: host+'/admin/office',
			data:{
				"id":that.data.hid
			},
			success(res)
			{
				console.log(res)
				that.setData({
					offices:res.data.data
				})
			}
		})
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		console.log(options)
		this.setData({
			hid:options.hid,
			hname:options.hname
		})
		this.getOfficeList()
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})